package com.xy.p2p.action.admin;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.octo.captcha.service.CaptchaServiceException;
import com.octo.captcha.service.image.ImageCaptchaService;
import com.xy.common.page.Pagination;
import com.xy.common.util.DictUtils;
import com.xy.common.security.BadCredentialsException;
import com.xy.common.security.UsernameNotFoundException;
import com.xy.common.web.CookieUtils;
import com.xy.common.web.RequestUtils;
import com.xy.core.web.WebErrors;

import com.xy.p2p.model.Tmembercreditassess;
import com.xy.p2p.service.TmembercreditassessService;



@Controller
public class TmembercreditassessAction{
	private static final Logger log = LoggerFactory.getLogger(TmembercreditassessAction.class);
	public TmembercreditassessAction() {
	}
 
 
 	/**
	 * 会员信用评分表新增页面
	 * 
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("v_tmembercreditassessAdd.do")
	public String add(HttpServletRequest request, ModelMap model) {
		model.addAttribute("tmembercreditassess", new Tmembercreditassess());
        setDict(model);
		return "tmembercreditassessEdit";
	}

	/**
	 * 会员信用评分表新增保存
	 * 
	 * @param tmembercreditassess
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/o_tmembercreditassessSave.do")
	public String save(Tmembercreditassess tmembercreditassess, HttpServletRequest request, ModelMap model) {
		WebErrors errors = validateSave(tmembercreditassess, request);
		if (errors.hasErrors()) {
			return errors.showErrorPage(model);
		}
		tmembercreditassess = tmembercreditassessService.save(tmembercreditassess);
		return "redirect:v_tmembercreditassessList.do";
	}

	/**
	 * 会员信用评分表删除
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping("o_tmembercreditassessDelete.do")
	public String delete(long[] ids) {
		if (ids != null) {
			for (long id : ids) {
				tmembercreditassessService.remove(id);
			}
		}
		return "redirect:v_tmembercreditassessList.do";
	}

	/**
	 * 会员信用评分表编辑页面
	 * 
	 * @param mcaid
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("v_tmembercreditassessEdit.do")
	public String edit(long mcaid, HttpServletRequest request, ModelMap model) {
		Tmembercreditassess tmembercreditassess = tmembercreditassessService.get(mcaid);
		model.addAttribute("tmembercreditassess", tmembercreditassess);
        setDict(model);
		return "tmembercreditassessEdit";
	}

	/**
	 * 会员信用评分表详情
	 * 
	 * @param mcaid
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("v_tmembercreditassessDetail.do")
	public String detail(long mcaid, HttpServletRequest request, ModelMap model) {
		Tmembercreditassess tmembercreditassess = tmembercreditassessService.get(mcaid);
		model.addAttribute("tmembercreditassess", tmembercreditassess);
        setDict(model);
		return "tmembercreditassessView";
	}

	/**
	 * 会员信用评分表查询（分页）
	 * 
	 * @param tmembercreditassess
	 * @param pageNo
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("v_tmembercreditassessList.do")
	public String listPage(Tmembercreditassess tmembercreditassess, Integer pageNo,
			HttpServletRequest request, ModelMap model) {
		if (pageNo == null)
			pageNo = 1;
		Pagination pagination = tmembercreditassessService.getTmembercreditassessByPage(toMap(tmembercreditassess),
				pageNo, CookieUtils.getPageSize(request));
		model.addAttribute("pagination", pagination);
        setDict(model);
		return "tmembercreditassessList";
	}

	/**
	 * 会员信用评分表查询
	 * 
	 * @param tmembercreditassess
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("v_tmembercreditassessList1.do")
	public String list(Tmembercreditassess tmembercreditassess, HttpServletRequest request, ModelMap model) {
		List<Tmembercreditassess> list = tmembercreditassessService.getTmembercreditassess(toMap(tmembercreditassess));
		model.addAttribute("list", list);
        setDict(model);
		return "tmembercreditassessList";
	}


 	/***
	 * 将页面输入信息转成map
	 * 
	 * @param tmembercreditassess
	 * @return
	 */	private Map<String,Object> toMap(Tmembercreditassess tmembercreditassess){
		Map<String,Object> map=new HashMap<String, Object>();
      		if(tmembercreditassess.getMcaid()!=null&&!tmembercreditassess.getMcaid().equals("")){
			map.put("mcaid", tmembercreditassess.getMcaid());
		}
		if(tmembercreditassess.getTmember()!=null&&!tmembercreditassess.getTmember().equals("")){
			map.put("Tmember", tmembercreditassess.getTmember());
		}
		if(tmembercreditassess.getCreditscore()!=null&&!tmembercreditassess.getCreditscore().equals("")){
			map.put("creditscore", tmembercreditassess.getCreditscore());
		}
		if(tmembercreditassess.getCreditrating()!=null&&!tmembercreditassess.getCreditrating().equals("")){
			map.put("creditrating", tmembercreditassess.getCreditrating());
		}
		if(tmembercreditassess.getTotalcredits()!=null&&!tmembercreditassess.getTotalcredits().equals("")){
			map.put("totalcredits", tmembercreditassess.getTotalcredits());
		}      
		return map;
	}
   
	/**
	 * 设置页面所需的数据字典
	 * @param model
	 */
	private void setDict(ModelMap model){
		
	}

	/**
	 * 数据校验
	 * @param model
	 */
	private WebErrors validateSave(Tmembercreditassess tmembercreditassess, HttpServletRequest request) {
		WebErrors errors = WebErrors.create(request);
		/**if (errors.ifOutOfLength(username, "username", 1, 100)) {
			return errors;
		}  */    
		return errors;
	}

   
      
	@Resource
	private TmembercreditassessService tmembercreditassessService;   
}